package com.liuyi.netty.im.lychat.modular.caches;

import com.alicp.jetcache.anno.CacheInvalidate;
import com.alicp.jetcache.anno.Cached;
import com.liuyi.netty.im.lychat.modular.entity.UserFriend;
import com.liuyi.netty.im.lychat.modular.service.IUserFriendService;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * 好友缓存
 *
 * @author Mr.Fmy
 * @since 2021/12/30
 */
@Service
public class UserFriendCache {

    @Resource
    @Lazy
    private IUserFriendService userFriendService;

    @Cached(name = "UserFriend:", key = "'getByUserIdAndFriendUserId:'+#userId+':'+#friendUserId")
    public UserFriend getByUserIdAndFriendUserId(String userId, String friendUserId) {
        UserFriend userFriend = userFriendService.getOne(userFriendService.q().eq(UserFriend.USER_ID, userId).eq(UserFriend.FRIEND_USER_ID, friendUserId).last("limit 1"));
        userFriendService.wrapper(userFriend);
        return userFriend;
    }

    @CacheInvalidate(name = "UserFriend:", key = "'getByUserIdAndFriendUserId:'+#userId+':'+#friendUserId")
    public void removeUserIdAndFriendUserId(String userId, String friendUserId) {
    }


}
